package com.qdsg.ysg.doctor.ui;

import android.os.Bundle;
import android.view.View;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.qdsg.ysg.doctor.R;
import com.qdsg.ysg.doctor.base.BaseActivity;
import com.qdsg.ysg.doctor.ui.dialog.SendSmsDialog;
import com.qdsg.ysg.doctor.util.ToastUtil;
import com.qdsg.ysg.doctor.util.UtilString;
import com.rest.business.RestProxy;
import com.rest.response.BaseResponse;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;
import io.reactivex.Observer;
import io.reactivex.disposables.Disposable;

/**
 * @time 2020/11/25 11:14
 * Created by lbj on 2020/11/25 11:14.
 */
public class SendMessageActivity extends BaseActivity {
    @BindView(R.id.tv_title)
    TextView tvTitle;
    @BindView(R.id.rl_baodao)
    LinearLayout rlBaodao;
    @BindView(R.id.rl_online)
    LinearLayout rlOnline;
    @BindView(R.id.rl_sure_chufang)
    LinearLayout rlSureChufang;
    private String outpId;

    @Override
    protected void initViews() {
        tvTitle.setText( "短信通知" );
    }

    @Override
    protected void initData() {
        outpId = getIntent().getStringExtra( "outpId" );

    }

    @Override
    protected int getLayoutResource() {
        return R.layout.aty_send_mes;
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate( savedInstanceState );
        // TODO: add setContentView(...) invocation
        ButterKnife.bind( this );
    }

    @OnClick({R.id.rl_baodao, R.id.rl_online, R.id.rl_sure_chufang})
    public void onViewClicked(View view) {
        switch (view.getId()) {
            case R.id.rl_baodao:
                if (!UtilString.isEmpty( outpId )) {
                    showSendSmsDialog( "1" );
                }
                break;
            case R.id.rl_online:
                if (!UtilString.isEmpty( outpId )) {
                    showSendSmsDialog( "2" );
                }
                break;
            case R.id.rl_sure_chufang:
                if (!UtilString.isEmpty( outpId )) {
                    showSendSmsDialog( "3" );
                }
                break;
        }
    }

    private void showSendSmsDialog(String type) {
        SendSmsDialog sendSmsDialog = SendSmsDialog.newInstance( type );
        sendSmsDialog.show( getSupportFragmentManager(), "sendSmsDialog" );
        sendSmsDialog.setmListener( new SendSmsDialog.OnItemClickListener() {

            @Override
            public void onConfirm() {
                sendSms( type );
            }

            @Override
            public void onCancel() {
                finish();
            }
        } );
    }


    private void sendSms(String type) {
        RestProxy.getInstance().sendSms( outpId, type, new Observer<BaseResponse>() {
            @Override
            public void onSubscribe(Disposable d) {
            }

            @Override
            public void onNext(BaseResponse baseResponse) {
                ToastUtil.showToast( mContext, "发送成功" );
                finish();
            }

            @Override
            public void onError(Throwable e) {
                ToastUtil.onError( mContext, e );

            }

            @Override
            public void onComplete() {

            }
        } );
    }
}
